<?php
namespace Admin\Controller;

class IconController extends CommonController {
    public function index(){
        $this->assign('title','英雄图片');
        $list = M('icon');
        $data = $list->select();
        $this->assign('data',$data);
        $this->show();
    }

    public function edit()
    {
        // var_dump($_POST);die;
          // 得到自定的模型类
                $upload = new \Think\Upload();// 实例化上传类
                $upload->maxSize = 3145728 ;// 设置附件上传大小
                $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
                $upload->rootPath = './Public/Uploads/'; // 设置附件上传根目录
                $upload->savePath = ''; // 设置附件上传（子）目录
                $upload->replace = 'true';//存在同名图片 覆盖
                $upload->subName = 'icon';
                // 上传文件
                $info = $upload->upload();
                if(!$info) {// 上传错误提示错误信息
                $this->error($upload->getError());
                }else{// 上传成功 获取上传文件信息
                    // foreach($info as $file){
                    $head = $info['icon']['savename'];
                    $s1 = $info['s1']['savename'];
                    $s2 = $info['s2']['savename'];
                    $s3 = $info['s3']['savename'];
                    $s4 = $info['s4']['savename'];
                }
                $icon = M('icon');
                // 取得成功上传的文件信息
                $info = $upload->upload();
                // 保存当前数据对象
                // $icon->
                if($head!=null){
                $data['icon'] = $head;
                }
                if($s1!=null){
                $data['s1_icon'] =$s1;
                }
                if($s2!=null){
                $data['s2_icon'] =$s2;
                }
                if($s3!=null){
                $data['s3_icon'] =$s3;
                }
                if($s4!=null){
                $data['s4_icon'] =$s4;
                }
                $where['c_id'] = $_POST['c_id'];
                 $re = $icon->where($where)->save($data);
                 if($re>0){
               $this->redirect('Admin/Icon/index');
                 }else{
                    return false;
                 }
        }

    



}   